package tk.zater;

import java.io.IOException;
import java.lang.annotation.Target;
import java.util.Scanner;

import org.apache.log4j.Logger;
import org.aspectj.weaver.patterns.IfPointcut.IfFalsePointcut;
import org.springframework.beans.factory.annotation.Autowired;

import tk.zater.CS.Constant;
import tk.zater.CS.GetUserKey;
import tk.zater.CS.UserAccountManagermant;

public class Userstrategy {
	@Autowired
	private Constant cs;
	private Logger logger = Logger.getLogger(Userstrategy.class);

	public void dealProcess() {
		if ("DoNothing".equals(cs.Accountstrategy)) {
			return;
		}
		if (cs.Accountstrategy.toLowerCase().endsWith("exe|bat")) {
			try {
				Process ps = Runtime.getRuntime().exec(cs.Accountstrategy);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				logger.error("找不到该文件");
			}

		} else {
			Object target = null;
			try {
				target = Class.forName(cs.Accountstrategy).newInstance();
			} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
				logger.error("找不到这个类" + cs.Accountstrategy);
			}
			if (target instanceof GetUserKey) {
				GetUserKey run=(GetUserKey)target;
				Scanner scn = new Scanner(run.run());
				while (scn.hasNextLine()) {
					String p=scn.nextLine().trim();
					if(p.contains("=")){
					String userinfo[]=	p.split("=");
						UserAccountManagermant.userAccount.put(userinfo[0], userinfo[1]);
						
					}
				}	
			} else {
				logger.error(cs.Accountstrategy + "并没有实现相关方法");

			}

		}
	}
}
